package com.ldx.single;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

//enum jdk1.5 本身也是一个类
public enum EnumSingle {

    INSTANCE;

    public EnumSingle getInstance() {
        return INSTANCE;
    }
}

class Test {

    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        EnumSingle instance1 = EnumSingle.INSTANCE;
//        Constructor<EnumSingle> declaredConstructor = EnumSingle.class.getDeclaredConstructor(null);
        Constructor<EnumSingle> declaredConstructor = EnumSingle.class.getDeclaredConstructor(String.class, int.class);// java.lang.IllegalArgumentException: Cannot reflectively create enum objects
        declaredConstructor.setAccessible(true);
        EnumSingle instance2 = declaredConstructor.newInstance();

//        java.lang.NoSuchMethodException: com.ldx.single.EnumSingle.<init>()
        System.out.println(instance1);
        System.out.println(instance2);

    }
}
